
<template>
  <Card class="card_style" :bordered="false" :dis-hover="true">
    <Row class="bench_search">
      <Col span="6" offset="1">
        <span>窗口：</span>
        <Input style="width: 70%;" v-model="windowno" />
      </Col>
      <Col span="6" offset="1">
        <span>员工号：</span>
        <Input style="width: 70%;" v-model="loginName" />
      </Col>
      <Button class="new-btn-sty" @click="searchData" style="margin-right:10px"><Icon type="ios-search" /> 搜索</Button>
    </Row>
    <Table border :columns="columns1" :data="datalist"></Table>
    <Row v-if="loadData === true">
      <Col class="demo-spin-col" span="8" offset="8">
        <Spin fix>
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>数据正在加载</div>
        </Spin>
      </Col>
    </Row>
    <Page :total="totalnum" :current="currentPageNo" :page-size="currentPageSize" @on-change="change" class="page_style" show-total  show-sizer @on-page-size-change="size"/>
  </Card>
</template>

<script>
import { findLineUpTodayList } from '@/api/eventlist'

export default {
  name: 'lineuptoday',
  data () {
    return {
      systemTime: '',
      loadData: true,
      windowno: '',
      loginName: '',
      currentPageNo: 1,
      currentPageSize: 10,
      totalnum: 0,
      paramData: {},
      columns1: [
        { title: '序号', type: 'index', width: 70, align: 'center' },
        { title: '姓名', key: 'name', width: 150, align: 'center' },
        { title: '身份证号', key: 'card_no', width: 200, align: 'center' },
        { title: '手机号', key: 'mobile', width: 150, align: 'center' },
        { title: '办理人员', key: 'loginName', width: 100, align: 'center' },
        { title: '叫号时间', key: 'calling_date', width: 150, align: 'center' },
        { title: '窗口号', key: 'window_no', width: 100, align: 'center' },
        { title: '开始时间', key: 'start_time', width: 150, align: 'center' },
        { title: '结束时间', key: 'end_time', width: 150, align: 'center' },
        { title: '等候时间', key: 'waittime', width: 150, align: 'center' },
        { title: '服务时间', key: 'servicetime', width: 150, align: 'center' }
      ],
      datalist: []
    }
  },
  methods: {
    init (param) {
      let that = this
      param.date = that.systemTime
      param.pageNo = that.currentPageNo
      param.pageSize = that.currentPageSize
      findLineUpTodayList(param).then(res => {
        if (res.data.errcode === 0) {
          let datalistcopy = []
          res.data.data.results.forEach(item => {
            console.log(item)
            let t2 = item.servicetime
            if (item.servicetime !== '' && item.servicetime != null) {
              let myobj = that.SecondToDate(t2)
              that.$set(item, 'servicetime', myobj)
            } else {
              that.$set(item, 'servicetime', '')
            }
            let t3 = item.waittime
            if (item.waittime !== '' && item.waittime != null) {
              let myobj = that.SecondToDate(t3)
              that.$set(item, 'waittime', myobj)
              datalistcopy.push(item)
            } else {
              that.$set(item, 'waittime', '')
              datalistcopy.push(item)
            }
          })
          that.datalist = datalistcopy
          that.totalnum = res.data.data.totalRecord
          that.loadData = false
        } else {
          this.loadData = true
          this.$Notice.error({ title: '获取列表失败', desc: res.data.errmsg })
        }
      })
    },
    searchData () {
      let params = {
        windowno: this.windowno,
        loginName: this.loginName
      }
      this.currentPageNo = 1
      this.init(params)
    },
    change (pageNo) {
      this.currentPageNo = pageNo
      let params = {
        windowno: this.windowno,
        loginName: this.loginName
      }
      this.init(params)
      console.log(params)
    },
    size (pageSize) {
      this.currentPageSize = pageSize
      this.change()
    },
    getCurrentDate () {
      let nowDate = new Date()
      let date1 = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() + 1,
        date: nowDate.getDate()
      }
      this.systemTime = date1.year + '-' + date1.month + '-' + date1.date
    },
    SecondToDate (msd) {
      var time = msd
      if (time != null && time !== '') {
        if (time > 60 && time < 60 * 60) {
          time = parseInt(time / 60.0) + '分钟' + parseInt((parseFloat(time / 60.0) -
            parseInt(time / 60.0)) * 60) + '秒'
        } else if (time >= 60 * 60 && time < 60 * 60 * 24) {
          time = parseInt(time / 3600.0) + '小时' + parseInt((parseFloat(time / 3600.0) -
            parseInt(time / 3600.0)) * 60) + '分钟' +
            parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
              parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + '秒'
        } else if (time >= 60 * 60 * 24) {
          time = parseInt(time / 3600.0 / 24) + '天' + parseInt((parseFloat(time / 3600.0 / 24) -
            parseInt(time / 3600.0 / 24)) * 24) + '小时' + parseInt((parseFloat(time / 3600.0) -
            parseInt(time / 3600.0)) * 60) + '分钟' +
            parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
              parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + '秒'
        } else {
          time = parseInt(time) + '秒'
        }
      }
      return time
    }
  },
  mounted () {
    this.getCurrentDate()
    let param = {
    }
    this.init(param)
  }
}
</script>
<style>
.card_style {
  height: 100%;
  width: 100%;
  overflow: hidden;
  padding: 0px;
}
.page_style {
  margin-top: 10px;
  text-align: right;
}
.bench_search {
  margin-bottom: 10px;
}
.nopadding .ivu-table-cell {
  padding: 0px 0px;
}
.code-img1 {
  height: 60%;
  width: 90%;
  margin-left: 5%;
}
.new-btn-sty {
  margin-right: 5px;
  color: #fff;
  background-color: #235CA7;
  border-color: #235CA7;
  font-weight: 500;
}
</style>
